home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / appsource.lha / APlusPlus / TESTPRGS / intuition / GroupedButtons_test.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  5.8 KB  |  216 lines

  1. /******************************************************************************
  2.  *
  3.  *    $Source: apphome:RCS/TESTPRGS/intuition/GroupedButtons_test.cxx,v $
  4.  *
  5.  *    Demo for the A++ Library
  6.  *    Copyright (C) 1994 by Armin Vogt, EMail: armin@uni-paderborn.de
  7.  *
  8.  *    $Revision: 1.7 $
  9.  *    $Date: 1994/08/01 16:10:54 $
  10.  *    $Author: Armin_Vogt $
  11.  *
  12.  ******************************************************************************/
  13.  
  14.  
  15. #include <APlusPlus/exec/SignalResponder.h>
  16. #include <APlusPlus/intuition/GWindow.h>
  17. #include <APlusPlus/intuition/IntuiMessageC.h>
  18. #include <APlusPlus/intuition/ITransponder.h>
  19. #include <APlusPlus/graphics/GBorder.h>
  20. #include <APlusPlus/gadtools/GT_Boolean.h>
  21. #include <APlusPlus/graphics/RowColumnGroup.h>
  22.  
  23.  
  24. extern "C" {
  25. #include <dos/dos.h>
  26. }
  27.  
  28.  
  29. static const char rcs_id[] = "$Id: GroupedButtons_test.cxx,v 1.7 1994/08/01 16:10:54 Armin_Vogt Exp Armin_Vogt $";
  30.  
  31.  
  32. // a CTRL-C signal responder from the example in the docs
  33. class MySRSP : public SignalResponder
  34. {
  35.    private:
  36.       BOOL running;  // indicates a received user break to object users
  37.    public:
  38.       MySRSP() : SignalResponder(SIGBREAKB_CTRL_C,0)
  39.       { running = TRUE; }
  40.       ~MySRSP() {}
  41.  
  42.       //  overload the virtual 'signal received' action callback method.
  43.       void actionCallback()
  44.       {
  45.          puts("**Break");
  46.          running = FALSE;  // end WaitSignal loop
  47.       }
  48.  
  49.       // object users can check with this method if a user break has occurred
  50.       BOOL hasNotOccured() { return running==TRUE; }
  51. };
  52.  
  53.  
  54.  
  55. class MyWindow : public GWindow
  56. {
  57.    public:
  58.       MyWindow(OWNER,AttrList& attrs) : GWindow(owner,attrs)
  59.       {
  60.          modifyIDCMP(CLASS_NEWSIZE|CLASS_CLOSEWINDOW|CLASS_ACTIVEWINDOW|CLASS_SIZEVERIFY);
  61.       }
  62.  
  63.       void On_CLOSEWINDOW(const IntuiMessageC *msg);
  64.       void On_ACTIVEWINDOW(const IntuiMessageC *msg);
  65.       void On_SIZEVERIFY(const IntuiMessageC *msg);
  66.  
  67.       void handleIntuiMsg(const IntuiMessageC* imsg);
  68.  
  69.       // runtime type inquiry support
  70.       static const Intui_Type_info info_obj;
  71.       virtual const Type_info& get_info() const     // get the 'type_id' to an existing object
  72.          { return info_obj; }
  73.       static const Type_info& info()                // get the 'type_id' of a specific class
  74.          { return info_obj; }
  75.  
  76. };
  77.  
  78. intui_typeinfo(MyWindow, derived(from(GWindow)), rcs_id);
  79.  
  80.  
  81.  
  82.  
  83. void MyWindow::On_CLOSEWINDOW(const IntuiMessageC *msg)
  84. {
  85.    puts("CLOSEWINDOW.");
  86.    delete this;   // it is allowed for WindowCV class to destroy itself
  87. }
  88.  
  89. void MyWindow::On_ACTIVEWINDOW(const IntuiMessageC *msg)
  90. {
  91.    puts(title()); puts(" is ACTIVE.");
  92. }
  93.  
  94. void MyWindow::On_SIZEVERIFY(const IntuiMessageC *msg)
  95. {
  96.    puts("SIZEVERIFY. ");
  97. }
  98.  
  99. void MyWindow::handleIntuiMsg(const IntuiMessageC* imsg)
  100. {
  101.    switch (imsg->getClass())
  102.    {
  103.       case CLASS_CLOSEWINDOW :
  104.          On_CLOSEWINDOW(imsg); break;
  105.       case CLASS_ACTIVEWINDOW :
  106.          On_ACTIVEWINDOW(imsg); break;
  107.       case CLASS_SIZEVERIFY :
  108.          On_SIZEVERIFY(imsg); break;
  109.    }
  110.    GWindow::handleIntuiMsg(imsg);
  111. }
  112.  
  113.  
  114.  
  115. void APPmain(int argc,char* argv[]) // this is NOT "main()" !!
  116. {
  117.    MySRSP userBreak;
  118.  
  119.    NeXTBorder border;
  120.  
  121.    /* Per default a Window object has an IDCMP for CLOSEWINDOW
  122.     */
  123.    MyWindow *little = new MyWindow(OWNER_NULL,
  124.    AttrList(   WA_Title,"Window - close this to stop.",
  125.       WA_Width,300,
  126.       WA_Height,150,
  127.       WA_MinHeight,40,
  128.       WA_MinWidth,90,
  129.       WA_MaxHeight,1600,
  130.       WA_MaxWidth,1600,
  131.       /* These are already default values..
  132.       WA_DragBar,TRUE,
  133.       WA_SizeGadget,TRUE,
  134.       WA_DepthGadget,TRUE,
  135.       WA_CloseGadget,TRUE,
  136.       */
  137.       GOB_BorderObj(&border), // GBorder object defining the border/background rendering
  138.       GOB_BorderTitle,(UBYTE*)"RowColumnGroup", // these two tags go with
  139.       GOB_BackgroundColor,4,                    // the GBorder object.
  140.       TAG_END) );
  141.  
  142.    /* The child GraphicObjects of a Group gadget are placed within the
  143.     * Group gadget depending on the geometry management implemented in that
  144.     * very Group gadget class.
  145.     * 'RowColumnGroup' lines its childs up in a row considering their width
  146.     * and height in the arrangement.
  147.     */
  148.    RowColumnGroup *rcg = new RowColumnGroup(little,
  149.    AttrList(
  150.       GOB_LeftFromLeftOfParent,0,
  151.       GOB_TopFromBottomOfParent,-40,
  152.       GOB_RightFromRightOfParent,0,
  153.       GOB_BottomFromBottomOfParent,0,
  154.       TAG_END) );
  155.  
  156.    /* The object 'collector' collects all notification streams from the
  157.     * three GT_Boolean gadgets. These send an AttrList containing the 'GA_ID'
  158.     * attribute with the gadget ID.
  159.     */
  160.    class Collector : public ITransponder
  161.    {
  162.       protected:
  163.          void sendNotification(AttrList& attrs)
  164.          {
  165.             printf("GT_Boolean hit: GA_ID = %ld\n",attrs.getTagData(GA_ID,-1));
  166.          }
  167.    } collector;
  168.  
  169.  
  170.    /* For the GT_Boolean gadgets <GA_ID,1> will arive at the 'collector' for
  171.     * each button press
  172.     */
  173.    new GT_Boolean(rcg,
  174.    AttrList(
  175.       GOB_Width,80,
  176.       GOB_Height,20,
  177.       GA_Immediate,TRUE,
  178.       GA_RelVerify,TRUE,
  179.       GA_Text,(UBYTE*)" Save ",
  180.       GA_ID,1,                   // <GA_ID,1> will arive at the 'collector'
  181.       ITRANSPONDER(&collector),
  182.       TAG_END) );
  183.  
  184.    new GT_Boolean(rcg,
  185.    AttrList(
  186.       GOB_Width,80,
  187.       GOB_Height,20,
  188.       GA_Immediate,TRUE,
  189.       GA_RelVerify,TRUE,
  190.       GA_Text,(UBYTE*)" Use ",
  191.       GA_ID,2,
  192.       ITRANSPONDER(&collector),
  193.       TAG_END) );
  194.  
  195.    new GT_Boolean(rcg,
  196.    AttrList(
  197.       GOB_Width,80,
  198.       GOB_Height,20,
  199.       GA_Immediate,TRUE,
  200.       GA_RelVerify,TRUE,
  201.       GA_Text,(UBYTE*)" Cancel ",
  202.       GA_ID,3,
  203.       ITRANSPONDER(&collector),
  204.       TAG_END) );
  205.  
  206.    little->refreshGList();    // display all GraphicObjects
  207.  
  208.  
  209.    // Notice: "APPOK(little)" expands to "(little!=NULL && little->Ok())"
  210.  
  211.    while (userBreak.hasNotOccured() && APPOK(little))
  212.       SignalResponder::WaitSignal();
  213.  
  214.    puts("main() end.\n");
  215. }
  216.